<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>小飞象-订单管理-订单管理</title>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_810097_mgs6xzz1oj.css">
    <link rel="stylesheet" href="../css/common/reset.css">
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/header.css">
    <link rel="stylesheet" href="../css/common/nav.css">
    <link rel="stylesheet" href="../css/reset-layui.css">
    <link rel="stylesheet" href="../css/common/aside.css">
    <link rel="stylesheet" href="../css/common/content.css">
    <link rel="stylesheet" href="../css/orderMage.css">
</head>

<body>
    <header>
        <div class="wrapper">
            <div class="clearfix headerBox">
                <h1 class="fl logo">
                    <a href="">小飞象</a>
                </h1>
                <!-- <div class="fl alipayName">支付宝充值账号: <b class="redColor">156****8656</b>开户人: <b class="redColor">陈小窝</b></div> -->
                <div class="fr logOut">退出</div>
                <div class="fr userName"></div>
            </div>
        </div>
    </header>
    <div class="mhNav">
        <ul class="navMenuBox">
            <li>
                <a href="../index.html">
                    飞象首页
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    会员中心
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../member/basicInfo.html">基本资料</a>
                    </li>
                    <li>
                        <a href="../member/storeMage.html">店铺管理</a>
                    </li>
                    <li>
                        <a href="../member/readjustNum.html">调整单量</a>
                    </li>
                    <li>
                        <a href="/goodsMage.html">商品管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    计划管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../plan/newPlan.html">新建计划</a>
                    </li>
                    <li>
                        <a href="../plan/planMage.html">计划管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;" class="active">
                    订单管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="orderMage.html">订单管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    资金管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../capital/inAccout.html">账号充值</a>
                    </li>
                    <li>
                        <a href="../capital/transferMage.html">转账管理</a>
                    </li>
                    <li>
                        <a href="../capital/orderMage/dailyTaskDes.html">订单信息</a>
                    </li>
                    <li>
                        <a href="../capital/expressForm.html">获取快递底单</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="">在线客服</a>
            </li>
        </ul>
    </div>
    <div class="clearfix wrapper mainBomContent">
        <div class="asideMenu">
            <h2 class="title">
                <i class="iconfont icon--"></i> 订单管理
            </h2>
            <ul>
                <li class="active">
                    <a href="orderMage.html">订单管理</a>
                </li>
            </ul>
        </div>
        <div class="rightContent">
            <div class="orderMageView">
                <ul>
                    <li>
                        <p class="fl">任务编号：</p>
                        <p class="fl">
                            <input type="text" id="task_num">
                        </p>
                        <p class="fl">订单号：</p>
                        <p class="fl">
                            <input type="text" id="order_num">
                        </p>
                        <p class="fl">物流单号：</p>
                        <p class="fl">
                            <input type="text" id="logistics_num">
                        </p>
                        <div class="fl">
                            <label>发布时间：</label>
                            <input type="hidden" id="planBeginDate">
                            <input type="hidden" id="planEndDate">
                            <input class="laydate-icon" id="BeginDate" maxlength="16" name="BeginDate" type="text"
                                value="" style="width:110px;" readonly="" autocomplete="off" /> ~
                            <input class="laydate-icon" id="EndDate" maxlength="16" name="EndDate" type="text" value=""
                                style="width:110px;" readonly="" autocomplete="off" />
                        </div>
                        <p class="fl">
                            <input type="button" value="查询" class="btn sureBtn" lay-submit lay-filter="quireOrder">
                        </p>
                        <p class="fl">
                            <input type="button" value="刷新" class="btn editBtn" lay-submit lay-filter="refreshOrder">
                        </p>
                        <!-- <p class="fl">
                            <input type="submit" value="一键审核" class="btn sureBtn">
                        </p> -->
                    </li>
                </ul>
                <table class="layui-table">
                    <colgroup>
                        <col width="280">
                        <col width="120">
                        <col width="140">
                        <!-- <col width="100"> -->
                        <col width="100">
                        <col width="120">
                        <col width="100">
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>任务/订单编号</th>
                            <th>店铺名称</th>
                            <th>旺旺号信息</th>
                            <th>好评内容</th>
                            <!-- <th>追评内容</th> -->
                            <th>创建时间</th>
                            <th>订单状态</th>
                            <th>操作按钮</th>
                        </tr>
                    </thead>
                    <tbody class="orderInfo">
                    </tbody>
                </table>
                <div class="loadMore">
                    <button id="loadMore">加载更多</button>
                </div>
            </div>
        </div>
    </div>
    <style>
        .delHtml {
            display: none;
            padding: 30px 0;
        }

        .delHtml table {
            width: 100%;
            text-align: center;
        }

        .text-break {
            white-space: normal;
            word-wrap: break-word;
            word-break: break-all;
        }

        .ellipsis {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 100px;
        }
    </style>
    <div class="delHtml">
        <form class="layui-form">
            <table>
                <tbody class="delOrder">
                    <tr>
                        <td>
                            <div class="layui-form-item">
                                你确定删除这笔订单吗？
                            </div>
                            <div class="layui-form-item">
                                <!-- <input type="button" value="提交" class="btn sureBtn" lay-submit="" lay-filter="delOrderInfo">
                                <input type="button" value="返回" class="btn editBtn" id="closeIframe"> -->
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <!-- <script src="../js/jquery.min.js"></script> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery.cookie.js"></script>
    <script src="../js/dataRequest.js"></script>
    <script src="../js/timechange.js"></script>
    <script>
        var mid = $.cookie('id');
        console.log("mid", mid);
        if (mid == null || mid == "" || !mid || mid == undefined) {
            window.location.href = "/login.html";
        }
        $(".mhNav .navMenuBox > li > a").click(function (event) {
            if ($(this).siblings('ul').is(':visible')) {
                $(this).siblings('ul').stop(true, true).slideUp();
                $(this).removeClass('active')
            } else {
                $(this).siblings('ul').stop(true, true).slideDown().parents('li').siblings().find('ul').stop(
                    true, true).slideUp();
                $(this).addClass('active').parents('li').siblings().find('a').removeClass('active');
            }
        });
        layui.use(['jquery', 'form', 'upload', 'laydate'], function () {
            var $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                layer = layui.layer,
                pageNum = 1,
                pageSize = 10;
            // 获取订单列表
            getOrderList();
            // 订单查询
            form.on('submit(quireOrder)', function (data) {
                $(".orderInfo").html("");
                pageNum = 1;
                getOrderList();
                return false;
            });
            // 订单刷新
            form.on('submit(refreshOrder)', function (data) {
                $(".orderInfo").html("");
                pageNum = 1;
                var taskNum = $("#task_num").val("");
                var orderNum = $("#order_num").val("");
                var logisticsNum = $("#logistics_num").val("");
                var planStartTime = $("#planBeginDate").val("");
                var planEndTime = $("#planEndDate").val("");
                getOrderList();
                return false;
            });
            // 订单加载更多
            $("#loadMore").on("click", function () {
                pageNum++;
                getOrderList();
            });
            // 删除订单
            $(document).on("click", ".fDel", function () {
                var orderId = $(this).attr("val");
                console.log("订单Id", orderId);
                var _that = $(this);
                layer.open({
                    type: 1 //Page层类型
                    , area: ['500px', '200px']
                    , title: '删除订单'
                    , shade: 0.6 //遮罩透明度
                    // , anim: 1 //0-6的动画形式，-1不开启
                    , content: $('.delHtml')
                    , btn: ['确认', '取消']
                    , yes: function (index, layero) {
                        console.log("你是谁啊", _that);
                        $.ajax({
                            url: BASE_URL + MAP_URL + '/order/' + orderId,
                            type: 'delete',
                            dataType: 'json',
                            success: function (data) {
                                console.log("数据是谁", data.data);
                                var _Success = data.code;
                                if (_Success == 200) {
                                    layer.msg("删除成功");
                                    _that.parent("td").parent("tr").remove();
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                } else {
                                    layer.msg(data.data);
                                }
                            }
                        })
                    }
                });
            });
            // 设置好评
            $(document).on("click", ".fSetGoodContent", function () {
                var orderId = $(this).attr("val");
                console.log("订单Id", orderId);
                layer.open({
                    type: 2,
                    title: '设置好评',
                    area: ['600px', '320px'],
                    shadeClose: true,
                    offset: 'auto',
                    resize: false,
                    scrollbar: false,
                    maxmin: false,
                    content: ['orderMage/setGoodContent.html'],
                    success: function (layero, index) {
                        var iframe = window['layui-layer-iframe' + index];
                        iframe.child(orderId);
                    },
                    zIndex: layer.zIndex
                });
            });
            // 查看详情
            $(document).on("click", ".readMore", function () {
                var orderId = $(this).attr("val");
                console.log("订单Id", orderId);
                layer.open({
                    title: "功能正在开发",
                    content: "请耐心等待",
                    icon: 5,
                    area: ['300px', '160px'],
                    shadeClose: true,
                    shade: 0.8,
                });
                // return;
                // layer.open({
                //     type: 2,
                //     title: '设置好评',
                //     area: ['600px', '376px'],
                //     shadeClose: true,
                //     offset: 'auto',
                //     resize: false,
                //     scrollbar: false,
                //     maxmin: false,
                //     content: ['orderMage/setGoodContent.html'],
                //     success: function (layero, index) {
                //         var iframe = window['layui-layer-iframe' + index];
                //         iframe.child(orderId);
                //     },
                //     zIndex: layer.zIndex //重点1
                // });
            });
            // 商户名获取
            $.ajax({
                type: "get",
                url: BASE_URL + MAP_URL + "merchants/" + mid,
                dataType: 'json',
                success: function (data) {
                    if (data.data == null || !data.data) {
                        layer.msg('数据出错,请重新登录', {
                            icon: 5,//提示的样式
                            time: 6000, //6秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                            end: function () {
                                location.href = '/login.html';
                            }
                        });
                    } else {
                        $(".userName").html(data.data.loginId);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg("系统错误");
                }
            });
            function getOrderList() {
                var taskNum = $("#task_num").val();
                var orderNum = $("#order_num").val();
                var logisticsNum = $("#logistics_num").val();
                var planStartTime = $("#planBeginDate").val();
                var planEndTime = $("#planEndDate").val();
                var JdateJson = {};
                if (taskNum != "") {
                    JdateJson.taskNum = taskNum;
                }
                if (orderNum != "") {
                    JdateJson.orderNum = orderNum;
                }
                if (logisticsNum != "") {
                    JdateJson.logisticsNum = logisticsNum;
                }
                if (planStartTime != "") {
                    JdateJson.planStartTime = planStartTime;
                }
                if (planEndTime != "") {
                    JdateJson.planEndTime = planEndTime;
                }
                console.log("json", JdateJson);
                $.ajax({
                    url: BASE_URL + MAP_URL + 'order/' + pageNum + '/' + pageSize + '/?merchantsId=' + mid,
                    type: 'GET',
                    dataType: 'json',
                    // contentType: "application/json;charset=utf-8",
                    data: JdateJson,
                    success: function (data) {
                        console.log("订单数据:", data.data);
                        // return;
                        var _Success = data.code;
                        if (_Success == 200) {
                            if (data.data.list.length == 0) {
                                console.log(123);
                                $("#loadMore").parent().addClass("noload");
                                $("#loadMore").attr("disabled", true);
                                $("#loadMore").html("没有数据拉");
                                $("#loadMore").css("cursor", "not-allowed");
                            } else {
                                $("#loadMore").parent().removeClass("noload");
                                $("#loadMore").attr("disabled", false);
                                $("#loadMore").html("加载更多");
                                $("#loadMore").css("cursor", "pointer");
                            }
                            var str = "";
                            for (var i = 0; i < data.data.list.length; i++) {
                                var _orderList = data.data.list;
                                var courier_id = _orderList[i].courier_id == undefined ? '暂无' : _orderList[i].courier_id;
                                var default_high_praise = _orderList[i].default_high_praise == undefined ? '未设置' : _orderList[i].default_high_praise;
                                var status;
                                switch (status = _orderList[i].status) {
                                    case 0:
                                        status = "失败任务"
                                        break;
                                    case 1:
                                        status = "待操作"
                                        break;
                                    case 2:
                                        status = "待审核"
                                        break;
                                    case 3:
                                        status = "已完成"
                                        break;
                                    case 4:
                                        status = "评价任务"
                                        break;
                                    default:
                                        status = "无"
                                        break;
                                }
                                str += '<tr>';
                                str += '<td>';
                                str += '<p>任务编号：' +
                                    _orderList[i].task_num + '</p>';
                                str += '<p>订单编号：' + _orderList[i].order_num + '</p>';
                                str += '<p>快递编号：' + courier_id + '</p>';
                                str += '</td>';
                                str += '<td>';
                                str += '<p>' + _orderList[i].shop_name +
                                    '</p>';
                                str += '</td>';
                                str += '<td><span class="text-break">' + _orderList[i].bound_want + '</span></td>';
                                str += '<td><p class="ellipsis">' + default_high_praise + '</p></td>';
                                // str += '<td>暂未设置追评内容</td>';
                                str += '<td>'
                                // 未设置评价
                                if (_orderList[i].status === 3) {
                                    str += '<p class="blueColor">已设置好评</p>';
                                }
                                str += '<p>' + $.time.getTime(_orderList[i].create_time) +
                                    '</p>';
                                str += '</td>';
                                str += '<td>' + status + '</td>';
                                str += '<td>';
                                if (_orderList[i].status === 4) {
                                    str +=
                                        '<a href="javascript:void(0);" class="btn sureBtn fSetGoodContent" val=' + _orderList[i].id + '>';
                                    str += '设置好评内容</a>';
                                }
                                if (_orderList[i].status === 3) {
                                    str += '<a href="javascript:void(0);" class="btn readMore" val=' + _orderList[i].id + '>查看详情</a>';
                                }
                                str +=
                                    '<a href="javascript:void(0);" class="btn delBtn fDel" val=' + _orderList[i].id + '>';
                                str += '删除</a>';
                                str += '</td>';
                                str += '</tr>';
                            }
                            $(".orderInfo").append(str);
                        } else {
                            layer.msg(data.data);
                        }
                    },
                    error: function () {
                        layer.msg("系统错误");
                    }
                });
            }
            //日期范围
            var startDate = laydate.render({
                elem: '#BeginDate',
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm',
                max: "2099-12-31",
                done: function (value, date) {
                    endDate.config.min = {
                        year: date.year,
                        month: date.month - 1,
                        date: date.date,
                        hours: 0,
                        minutes: 0,
                        seconds: 0
                    };
                    console.log("你是我选择的日期", value);
                    var BeginDateT = $.time.dataCommon(value);
                    $("#planBeginDate").val(BeginDateT);
                }
            });
            var endDate = laydate.render({
                elem: '#EndDate',
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm',
                done: function (value, date) {
                    startDate.config.max = {
                        year: date.year,
                        month: date.month - 1,
                        date: date.date,
                        hours: 0,
                        minutes: 0,
                        seconds: 0
                    }
                    console.log("你是我选择的日期", value);
                    var endDateT = $.time.dataCommon(value);
                    $("#planEndDate").val(endDateT);
                }
            });
        });
    </script>
</body>

</html>